package com.archgeek.rpc.grpc.service.impl;

import com.archgeek.rpc.grpc.service.GreetingServiceGrpc;
import com.archgeek.rpc.grpc.service.GreetingServiceOuterClass;
import io.grpc.stub.StreamObserver;

/**
 * @author pizhihui
 * @date 2024-05-23 17:04
 */
public class GreetingServiceImpl extends GreetingServiceGrpc.GreetingServiceImplBase {


    @Override
    public void greeting(GreetingServiceOuterClass.HelloRequest request,
                         StreamObserver<GreetingServiceOuterClass.HelloResponse> responseObserver) {

        System.out.println("request: " + request);

        GreetingServiceOuterClass.HelloResponse response = GreetingServiceOuterClass.HelloResponse.newBuilder()
                .setGreeting("Hello there, " + request.getName())
                .build();

        // Use responseObserver to send a single response back
        responseObserver.onNext(response);

        // When you are done, you must call onCompleted.
        responseObserver.onCompleted();

    }
}
